﻿#define _CRT_SECURE_NO_WARNINGS//链表
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct Node
{
	int cj;
	int num;
	char name[20];
	struct Node* next;
};
struct Node* creatlist()
{
	struct Node* headnode = (struct Node*)malloc(sizeof(struct Node));
	headnode->next = NULL;
	return headnode;
}
struct Node* creatnode(int cj, int num, char name[20])
{
	struct Node* newnode = (struct Node*)malloc(sizeof(struct Node));
	newnode->cj = cj;
	newnode->num = num;
	strcpy(newnode->name, name);
	newnode->next = NULL;
	return newnode;
}
struct Node* setnode(struct Node* head, int cj, int num, char name[20])
{
	struct Node* newnode = creatnode(cj, num, name);
	newnode->next = head->next;
	head->next = newnode;
	return newnode;
}

void printlist(struct Node* head)
{
	struct Node* p = head->next;
	printf("%s\t%s\t%s\n", "成绩", "学号", "姓名");
	while (p)
	{
		printf("%d\t%d\t%s\n", p->cj, p->num, p->name);
		p = p->next;
	}
}
struct Node* delenode(struct Node* head, int num)
{
	struct Node* node = head->next;
	struct Node* nodeford = head;
	if (node == NULL)
	{
		printf("该链表为空，不可删除！");
		return NULL;
	}
	while (node->num != num)
	{
		nodeford = node;
		node = node->next;
		if (node->next == NULL)
		{
			printf("没有该数据，无法删除！\n");
			return NULL;
		}
	}
	nodeford->next = node->next;
	free(node);
	return head;

}
void prints(struct Node* p1)
{
	printf("%s\t%s\t%s\n", "成绩", "学号", "姓名");
	printf("%d\t%d\t%s\n", p1->cj, p1->num, p1->name);
}
void select(struct Node* head)
{
	struct Node* ps = head->next;
	struct Node* p2 = head->next;
	while (p2->next)
	{
		if (ps->cj < p2->cj)
		{
			ps = p2;
		}
		else
		{
			p2 = p2->next;
		}

	}
	prints(ps);
}
int main()
{
	struct Node* list = creatlist();
	struct Node* ret = list;
	for (int i = 0; i < 7; i++)
	{
		int cj = 0;
		int num = 0;
		char name[20] = { 0 };
		scanf("%d %d %s", &cj, &num, &name);
		ret = setnode(ret, cj, num, name);
	}
	printlist(list);
	select(list);
	/*delenode(list, 4);
	printlist(list);*/
	return 0;
}